﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using Exam.Core.DBUtility;
using System.Xml;

namespace Exam.Core.SQLDAL {
    public class TacticsQuestionType {

        private readonly string path = FilePath.QuestionTypeXmlPath.Trim();

        /// <summary>
        /// 题型列表
        /// </summary>
        /// <param name="courseid"></param>
        /// <returns></returns>
        public List<Exam.Core.Model.TacticsQuestionType> getList(int courseid) {

            List<Exam.Core.Model.TacticsQuestionType> list = new List<Exam.Core.Model.TacticsQuestionType>();

            string SQL = "SELECT DISTINCT QuestionTypeId FROM Question WHERE CourseId=" + courseid;
            DataTable dt = DbHelperSQL.Query(SQL).Tables[0];
            XmlDocument doc = XmlHelper.GetXmlDocument(path);
            XmlNodeList nodeList = doc.GetElementsByTagName("questiontype");
            foreach (DataRow dr in dt.Rows) {
                foreach (XmlNode node in nodeList) {
                    if (node.Attributes["id"].Value.Trim() == dr["QuestionTypeId"].ToString().Trim()) {
                        Exam.Core.Model.TacticsQuestionType obj = new Exam.Core.Model.TacticsQuestionType();
                        obj.QuestionTypeId = node.Attributes["id"].Value.Trim();
                        obj.QuestionTypeTitle = node.Attributes["title"].Value.Trim();
                        obj.QuestionTypeAttr = node.Attributes["questiontypeattr"].Value.Trim();
                        obj.QuestionCount = new Exam.Core.SQLDAL.Question().getCountByType(obj.QuestionTypeId);
                        obj.TacticsKnowledges = new TacticsKnowledges().getListByTypeId(obj.QuestionTypeId, courseid.ToString());//该题型下知识点列表
                        list.Add(obj);
                    }
                }
            }

            return list;
            
        }
    }
}
